package main.java;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class RegexChecker {

	/**
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException {

		String fileContent = getFileContent("files/dp_01.gsi");
		fileContent += getFileContent("files/dp_01_coor.gsi");

		System.out.println("GSI file content:");
		System.out.println();
		System.out.println(fileContent);
		System.out.println();

		String out = "*410000+00000000000000AN 42....+00000000DPUE2012\n";
		out += "*410001+00000000000DATUM 42....+2012-05-10 22:19\n"
				+ "*410002+00SACHBEARBEITER 42....+00000000Jane Doe\n"
				+ "*410003+000000INSTRUMENT 42....+000000000TPS1200\n"
				+ "\n"
				+ "*110004+0000000000dp_001 21.322+0000000003012287 22.322+0000000010000008 31..08+0000000000300000 51..10+000000000000+000 58..16+0000000000000000 47....+Leica Circ Prism PPMATM+0000000000000000 PPMGEO+0000000000000000 59..1.+0000000000000000";

		System.out.println("Regex check result: " + out.matches("(\\*.{23}(\\s.{23})*(\\s)*(\\n)?|(\\n)?)*"));
		System.out.println();
		System.out.println("Regex check result: " + fileContent.matches("(\\*.{23}(\\s.{23})*(\\s)*(\\n)?|(\\n)?)*"));
	}

	private static String getFileContent(String filePath) throws FileNotFoundException
	{
		StringBuilder text = new StringBuilder();
		String lineSeparator = System.getProperty("line.separator");
		Scanner scanner = new Scanner(new FileInputStream(filePath));
		try
		{
			while (scanner.hasNextLine())
			{
				text.append(scanner.nextLine() + lineSeparator);
			}
		}
		finally
		{
			scanner.close();
		}

		String fileContent = text.toString();
		return fileContent;
	}

}
